using System;
using System.Windows.Controls;
using System.Windows.Threading;
using System.Deployment.Application;

public partial class Page1 : Page
{
    public Page1()
    {
        InitializeComponent();
    }

    protected override void OnInitialized(EventArgs e)
    {
        base.OnInitialized(e);
        if (ApplicationDeployment.IsNetworkDeployed)
        {
            // Handle the event that is raised when the download of files
            // in MyGroup is complete.
            ApplicationDeployment.CurrentDeployment.DownloadFileGroupCompleted +=
            delegate
            {
                // Were on a different thread, so invoke GotoPage2 on the UI thread
                Dispatcher.BeginInvoke(DispatcherPriority.Send,
                new DispatcherOperationCallback(GotoPage2), null);
            };
            ApplicationDeployment.CurrentDeployment.DownloadFileGroupAsync("MyGroup");
        }
        else
        {
            // Were not running in the context of ClickOnce (perhaps because
            // were being debugged), so just go directly to Page2.
            GotoPage2(null);
        }
    }
 
    // Navigates to Page2 when ready. Accepts and returns an object simply
    // to match the signature of DispatcherOperationCallback
    private object GotoPage2(object o)
    {
        return NavigationService.Navigate(new Uri("Page2.xaml", UriKind.Relative));
    }
}